Imports Microsoft.VisualBasic

Public Class CLS_BALANCE_TOTAL
    Dim Conn As New Connect                         'New Object Connect
    Dim fcn As New CLS_FCN                          'New Object CLS_FCN

    Dim AMOUNT As Decimal = 5000000
    Dim PAY As Decimal
    Dim WITHDRAW As Decimal
    Dim TOTAL As Decimal

    Function PayMoney()
        Dim SQL As String = "SELECT SUM(wd.WTD_DTL_AMOUNT) AS allPAY " & _
                            "FROM PTY_DAT_WTD w,PTY_DAT_WTD_DTL wd " & _
                            "WHERE(w.WTD_ID = wd.WTD_ID) " & _
                            "AND w.WTD_STATUS='4' "
        Me.PAY = Conn.GetData(SQL, "allPAY", 0)
        Return Me.PAY
    End Function

    Function WithDrawMoney()
        Dim SQL As String = "SELECT SUM(wd.WTD_DTL_AMOUNT) AS wtdCHQ " & _
                            "FROM PTY_DAT_CHQ_WTD cw,PTY_DAT_CHQ cq, " & _
                            "PTY_DAT_WTD w,PTY_DAT_WTD_DTL wd " & _
                            "WHERE(cw.CHQ_NO = cq.CHQ_NO) " & _
                            "AND w.CHQ_ID=cq.CHQ_ID " & _
                            "AND w.WTD_ID=wd.WTD_ID "
        Me.WITHDRAW = Conn.GetData(SQL, "wtdCHQ", 0)
        Return Me.WITHDRAW
    End Function
    Function AmountTotal()
        Me.TOTAL = (Me.AMOUNT - PayMoney()) + WithDrawMoney()
        Return Me.TOTAL
    End Function
End Class
